<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2025/10/15
  Time: 14:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>评论管理</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/back-index.css" />
    <script src="${pageContext.request.contextPath}/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-paginator.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap-mypaginator.js"></script>

    <script type="text/javascript">
        $(function(){
        $("#back").on('click', function(){
        location.href = "${pageContext.request.contextPath}/Chapter/findByCourseId?courseId=${courseId}&pageNo=1";
        });
            // 展开搜索
            $('#show-comment-search').click(function() {
                $('#show-comment-search').hide();
                $('#upp-comment-search').show();
                $('.show-comment-search').slideDown(500);
            });
            
            // 收起搜索
            $('#upp-comment-search').click(function() {
                $('#show-comment-search').show();
                $('#upp-comment-search').hide();
                $('.show-comment-search').slideUp(500);
            });

            //启用与禁用
            $("input[name='modifyStatus']").click(function () {
                $.ajax({
                    type: "post",
                    url: "${pageContext.request.contextPath}/comment/modifyStatus",
                    data: {
                        "id": $(this).attr("data-id"),
                        "status": $(this).attr("data-status")
                    },
                    dataType: "json",
                    success: function (result) {
                        if (result.responseCode == "2001") {
                            location.href = "${pageContext.request.contextPath}/comment/findAll?pageNo=${commentPage2.pageNum == 0 ? 1 : commentPage2.pageNum}";
                        } else {
                            $("#errorMsg").html(result.message);
                        }
                    }
                })
            });


            <%--$("#commentPageHelper").bootstrapPaginator({--%>
            <%--    bootstrapMajorVersion: 3,--%>
            <%--    currentPage: "${commentPage2 != null ? (commentPage2.pageNum == 0 ? 1 : commentPage2.pageNum) : 1}",--%>
            <%--    totalPages: "${commentPage2 != null ? (commentPage2.pages == 0 ? 1 : commentPage2.pages) : 1}",--%>
            <%--    size: "normal",--%>
            <%--    alignment: "center",--%>
            <%--    onPageClicked: function (event, originalEvent, type, page) {--%>
            <%--        $("#pageNo").val(page);--%>
            <%--        $("#searchForm").submit();--%>
            <%--    }--%>
            <%--});--%>

            <%--$("#doSearch").click(function() {--%>
            <%--    console.log("搜索表单提交，resourceId: " + "${resourceId}");--%>
            <%--    $("#search_resource_id").val("${resourceId}");--%>
            <%--    $("#searchForm").submit();--%>
            <%--});--%>


            $("#doSearch").click(function() {
                $("#search_resource_id").val("${resourceId}");
                $("#searchForm").submit();
            });


            $("#commentPageHelper").bootstrapPaginator({
                bootstrapMajorVersion: 3,
                currentPage: "${commentPage2.pageNum == 0 ? 1 : commentPage2.pageNum}",
                totalPages: "${commentPage2.pages == 0 ? 1 : commentPage2.pages}",
                size: "normal",
                alignment: "center",
                onPageClicked: function (event, originalEvent, type, page) {
                    $("#pageNo").val(page);
                    $("#searchForm").submit();
                }
            });

















        })
    </script>
</head>

<body>
<div class="panel panel-default" id="userSet">
    <div class="panel-heading">
        <h3 class="panel-title">评论管理</h3>
    </div>
    <div>
        <!-- course-resource-id,没有时,移除此按钮 -->
        <input type="hidden" name="course_resource_id" value=""  />
        <input type="button" value="查询" class="btn btn-success" id="doSearch" style="margin: 5px 5px 5px 15px;" />
        <input type="button" class="btn btn-primary" id="show-comment-search" value="展开搜索" />
        <input type="button" value="收起搜索" class="btn btn-primary" id="upp-comment-search" style="display: none;" />
        <input type="button" value="返回章节列表" class="btn btn-success" id="back" style="margin: 5px 15px 5px 0px;float: right;" />
    </div>

    <div class="panel-body">
        <div class="show-comment-search" style="display: none;">
            <form class="form-horizontal" id="searchForm">
                <input type="hidden" name="resourceId" id="search_resource_id" value="${resourceId}" />
                <input type="hidden" name="pageNo" id="pageNo" value="1" />
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <label for="user-name-search" class="col-xs-3 control-label">用户名：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="user-name-search" placeholder="请输入用户名" name="userName" />
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label for="user-comment-search" class="col-xs-3 control-label">内容：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" id="user-comment-search" placeholder="请输入评论内容" name="content" />
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <label class="col-xs-3 control-label">开始日期：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" placeholder="请输入开始时间:2017-10-10"  name="createStartDate"/>
                        </div>
                    </div>
                    <div class="form-group col-xs-6">
                        <label class="col-xs-3 control-label">结束日期：</label>
                        <div class="col-xs-8">
                            <input type="text" class="form-control" placeholder="请输入结束时间:2017-10-12"  name="createEndDate"/>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="form-group col-xs-6">
                        <label for="course-resource-stauts-search" class="col-xs-3 control-label">状态：</label>
                        <div class="col-xs-8">
                            <select class="form-control" id="course-resource-stauts-search" name="status" >
                                <option value="-1" >全部</option>
                                <option value="0" >启用</option>
                                <option value="1" >禁用</option>
                            </select>
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="show-list">
            <table class="table table-bordered table-hover" style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">编号</th>
                    <th class="text-center">评论内容</th>
                    <th class="text-center">用户名</th>
                    <th class="text-center">评论时间</th>
                    <th class="text-center">赞</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                <c:if test="${commentPage2 != null}">
                    <c:forEach items="${commentPage2.list}" var="comment">
                        <tr>
                            <td>${comment.id}</td>
                            <td>${comment.context}</td>
                            <td>${comment.userId}</td>
                            <td>${comment.createDate}</td>
                            <td>${comment.like}</td>
                            <td>${comment.status}</td>
                            <td class="text-center">
                                <c:if test="${comment.status == 1}">
                                    <input type="button" class="btn btn-danger btn-sm doCommentDisable" name="modifyStatus"
                                           data-id="${comment.id}" data-status="${comment.status}" value="禁用">
                                </c:if>
                                <c:if test="${comment.status == 0}">
                                    <input type="button" class="btn btn-success btn-sm doCommentEnable" name="modifyStatus"
                                           data-id="${comment.id}" data-status="${comment.status}" value="启用">
                                </c:if>
                            </td>
                        </tr>
                    </c:forEach>
                </c:if>
                
                <c:if test="${commentPage2 == null or empty commentPage2.list}">
                    <tr>
                        <td colspan="7" class="text-center">暂无评论数据</td>
                    </tr>
                </c:if>
                </tbody>
            </table>
            <ul id="commentPageHelper"></ul>
        </div>
    </div>
</div>
</body>
</html>
